package leo.game.ui
{
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	import leo.data.GameConst;
	/**
	 * 网格类 
	 * @author leo
	 * 
	 */	
	public class MapGrid extends Sprite
	{
		
		private var map_width :int;
		private var map_height :int;
		private var tile_width :int;
		private var tile_height :int;
		private var rows :int;
		private var cols :int;
		public function MapGrid()
		{
			super();
			this.map_width = GameConst.MAP_WIDTH;
			this.map_height = GameConst.MAP_HEIGHT;
			this.tile_width = GameConst.TILE_WIDTH;
			this.tile_height = GameConst.TILE_HEIGHT;
			this.rows = map_width/tile_width;
			this.cols = map_height/tile_height;
			
			//横线
			for(var y :int = 0; y < cols ; y++)
			{
				this.graphics.lineStyle(1,0);
				this.graphics.moveTo(0,y * tile_height);
				this.graphics.lineTo(map_width,y * tile_height);
			}
			//竖线
			for(var x :int = 0; x < rows; x++)
			{
				this.graphics.lineStyle(1,0);
				this.graphics.moveTo(tile_width * x,0);
				this.graphics.lineTo(tile_width * x,map_height);
			}
			this.graphics.endFill();
			
			//文本显示
			for(var y1 :int = 0; y1 < cols; y1++)
			{
				for(var x1 :int = 0; x1 < rows; x1++)
				{
					var dx :Number = x1 * tile_width;
					var dy :Number = y1 * tile_height;
					var txt :TextField = new TextField();
					txt.selectable = txt.border = false;
					txt.defaultTextFormat = new TextFormat(null,18,0,null,null,null,null,null,"center");
					txt.text = x1 + "," + y1;
					txt.width = tile_width;
					txt.height = tile_height/2;
					txt.x = dx;
					txt.y = dy;
					addChild(txt);
				}
			}
		}
	}
}